<?php


namespace app\admin\service\setting;

use app\common\model\log\QueueLog;
use tmcore\base\BaseService;
use tmcore\exceptions\ValidateException;

/**
 * 队列日志服务类
 */
class QueueService extends BaseService
{
    /**
     * 获取队列日志列表
     * @return array
     */
    public static function getList(): array
    {
        // 搜索条件
        $searchParam = [
            '%like%' => ['queue','job_name','job_id'],
            '=' => ['result'],
            'datetime' => ['create_time'],
        ];
        $where = self::getSearchData($searchParam, []);

        // 返回分页数据
        return QueueLog::page($where, self::getPageData(),'id,queue,job_name,job_id,result,result_msg,param,drive,execute_time,retry_num,create_time', ['id' => 'desc'], ['result_desc'] );
    }

    /**
     * 查看日志详情
     * @param $params
     * @return array
     */
    public static function detail($params) : array
    {
        if(empty($params['id'])) throw new ValidateException('参数异常');
        $row = QueueLog::where(['id' => $params['id']])->append(['result_desc'])->hidden(['backup'])
            ->findOrEmpty();
        if ($row->isEmpty()) return [];
        return $row->toArray();
    }
}